package com.ambulance.project.biz.controller.manager;

import com.ambulance.common.utils.poi.ExcelUtil;
import com.ambulance.framework.aspectj.lang.annotation.Log;
import com.ambulance.framework.aspectj.lang.enums.BusinessType;
import com.ambulance.framework.web.controller.BaseController;
import com.ambulance.framework.web.domain.AjaxResult;
import com.ambulance.framework.web.page.TableDataInfo;
import com.ambulance.project.manager.domain.BizHospital;
import com.ambulance.project.manager.service.IBizHospitalService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 外援Controller
 *
 * @author zr
 * @date 2020-05-12
 */
@RestController
@RequestMapping("/manager/hospital")
public class BizHospitalController extends BaseController {
    @Autowired
    private IBizHospitalService bizHospitalService;

    /**
     * 查询外援列表
     */
    //@PreAuthorize("@ss.hasPermi('manager:hospital:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizHospital bizHospital) {
        startPage();
        List<BizHospital> list = bizHospitalService.selectBizHospitalList(bizHospital);
        return getDataTable(list);
    }

    /**
     * 导出外援列表
     */
    //@PreAuthorize("@ss.hasPermi('manager:hospital:export')")
    @Log(title = "外援", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BizHospital bizHospital) {
        List<BizHospital> list = bizHospitalService.selectBizHospitalList(bizHospital);
        ExcelUtil<BizHospital> util = new ExcelUtil<BizHospital>(BizHospital.class);
        return util.exportExcel(list, "hospital");
    }

    /**
     * 获取外援详细信息
     */
    //@PreAuthorize("@ss.hasPermi('manager:hospital:query')")
    @GetMapping(value = "/{hospitalID}")
    public AjaxResult getInfo(@PathVariable("hospitalID") Long hospitalID) {
        return AjaxResult.success(bizHospitalService.selectBizHospitalById(hospitalID));
    }

    /**
     * 新增外援
     */
    //@PreAuthorize("@ss.hasPermi('manager:hospital:add')")
    @Log(title = "外援", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizHospital bizHospital) {
        System.out.println(bizHospital);
        return toAjax(bizHospitalService.insertBizHospital(bizHospital));
    }

    /**
     * 修改外援
     */
    //@PreAuthorize("@ss.hasPermi('manager:hospital:edit')")
    @Log(title = "外援", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizHospital bizHospital) {
        return toAjax(bizHospitalService.updateBizHospital(bizHospital));
    }

    //@PreAuthorize("@ss.hasPermi('manager:hospital:frost')")
    @Log(title = "冻结", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/frost")
    @ResponseBody
    public AjaxResult frost(@Param(value = "hospitalID") Long hospitalID) {

        return toAjax(bizHospitalService.frostBizHospitalById(hospitalID));
    }

    /**
     * 删除外援
     */
    //@PreAuthorize("@ss.hasPermi('manager:hospital:remove')")
    @Log(title = "外援", businessType = BusinessType.DELETE)
    @DeleteMapping("/{hospitalIDs}")
    public AjaxResult remove(@PathVariable Long[] hospitalIDs) {
        return toAjax(bizHospitalService.deleteBizHospitalByIds(hospitalIDs));
    }


}
